﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Collections.Specialized.BitVector32;

namespace Class4_work1
{
    public class Node<T>
    {
        public Node<T> Next
        {
            get;
            set;
        }
        public T Data { get; set; }
        public Node(T t)
        {
            Next = null;
            Data = t;
        }
    }
    public class GenericList<T>
    {
        private Node<T> head;
        private Node<T> tail;
        public GenericList()
        {
            tail = head = null;
        }
        public Node<T> Head
        {
            get => head;
        }
        public void ForEach(Action<T> action) {
            Node<T> t = this.head;
            while (t != null)
            {
                action(t.Data);
                t = t.Next;
            }
        }
        
        public void Add(T t)
        {
            Node<T> n = new Node<T>(t);
            if (tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.Next = n;
                tail = n;
            }
        }      
    }
    class Program
    {
        static void Main(string[] args)
        {
           
            GenericList<int> intlist = new GenericList<int>();
            for (int x = 0; x < 10; x++)
            {
                intlist.Add(x);
            }
            //打印数字
            intlist.ForEach(m => Console.WriteLine(m));
            //总和
            int sum = 0;
            intlist.ForEach(m => { sum += m; });
            Console.WriteLine($"总和：{sum}");
            //最大值
            int max = int.MinValue;
            intlist.ForEach(N => { if (max < N) max = N; });
            Console.WriteLine($"最大值：{max}");
            //最小值
            int min = int.MaxValue;
            intlist.ForEach(L => { if (min > L) min = L; });
            Console.WriteLine($"最小值：{min}");
            Console.ReadKey();
        }
    }
}
 

